<template>
  <div class="extend">
    <div class="section">
      <h3>待发放</h3>
      <SearchItem @searchList="searchData" :type="1"></SearchItem>
    </div>
    <el-table
      :height="tabHeight"
      border
      style="width: 100%"
      align="center"
      :data="tableData"
      @selection-change="selectTable"
      v-loading="loading"
    >
      <el-table-column type="selection" width="35"></el-table-column>
      <el-table-column prop="roId" label="ID" width="145"></el-table-column>
      <el-table-column prop="username" label="用户名" width="60"></el-table-column>
      <el-table-column prop="cpName" label="所属CP" width="60"></el-table-column>
      <el-table-column prop="gameName" label="游戏名" width="90"></el-table-column>
      <el-table-column prop="serverName" label="区服" width="90"></el-table-column>
      <el-table-column prop="roleName" label="角色名" width="110"></el-table-column>
      <el-table-column prop="roleId" label="角色ID"></el-table-column>
      <el-table-column prop="amount" label="申请金额" width="65"></el-table-column>
      <el-table-column prop="amountTotal" label="今日总金额" width="75"></el-table-column>
      <el-table-column prop="applyTime" label="申请时间"></el-table-column>
      <el-table-column prop="payTime" label="充值时间"></el-table-column>
      <el-table-column label="返利信息" width="60">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showdialog(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="玩家备注" width="60" prop="remark">
        <template slot-scope="scope">
          <el-button type="text" @click="showNotes(scope.row)" size="small">编辑</el-button>
        </template>
      </el-table-column>
      <el-table-column label="明细" width="60">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showdetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="80">
        <template slot-scope="scope">
          <el-button type="success" plain size="mini" @click="giveOut(scope.row)">发放</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="bottom">
      <!-- 将分页器作为子组件引入 -->
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="pagenationData.currentPage"
        :page-size="pagenationData.pageSize"
        :total="pagenationData.pageTotal"
        background
        layout="prev, pager, next"
        prev-text="上一页"
        next-text="下一页"
      ></el-pagination>
      <el-button type="success" @click="sendtoCP" class="sendtoCP">一键发放</el-button>
    </div>
    <!-- 查看返利信息 -->
    <ShowRebateDialog
     v-if="showRebateDialog.show"
      :isShow="showRebateDialog.show"
      :dialogRow="showRebateDialog.dialogRow"
      @closeDialog="hideRebateDialog"
    ></ShowRebateDialog>

    <!-- 返利明细 -->
    <DetailDialog
      v-if="detailDialog.show"
      :isShow="detailDialog.show"
      :dialogRow="detailDialog.dialogRow"
      @closeDialog="hideDetailDialog"
    ></DetailDialog>

    <!-- 玩家备注 -->
    <el-dialog
      :visible.sync="playerRemarkVisible"
      title="玩家备注"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :modal-append-to-body="false"
      width="30%"
      center
    >
      <el-form :model="form">
        <el-form-item>
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="playerRemark">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters } from "vuex";
import Pagenation from "@/components/pagenation/Pagenation";
import SearchItem from "@/components/search/SearchItem";
import ShowRebateDialog from "@/components/dialog/ShowRebateDialog";
import DetailDialog from "@/components/dialog/DetailDialog";
import {
  giveOutInline,
  onekeyExtend,
  getextendData,
  showrebateDetail,
  changePlayerRemark
} from "@/api/data";
export default {
  name: "extend",
  inject: ["reload"],
  components: {
    Pagenation,
    SearchItem,
    ShowRebateDialog,
    DetailDialog
  },
  data() {
    return {
      tabHeight: window.innerHeight - 200,
      pagenationData: {
        pageTotal: 0,
        currentPage: 1,
        pageSize: 20
      },
      multipleSelection: [], //复选框选中
      loading: true,
      playerRemarkVisible:false,
      formData: {
        //搜索条件
        playAccount: "",
        gameName: ""
      },
      showRebateDialog: {
        show: false,
        dialogRow: {}
      },
      detailDialog: {
        show: false,
        dialogRow: []
      },
      tableData: [],
      pageData: {
        page: 1,
        limit: 20
      },
      search: {},
      form: {
        remark: "",
        roId: Number
      }
    };
  },
 mounted() {
    this.getextendData();
  },
  methods: {
    searchData(search) {
      this.pagenationData.currentPage = 1;
      this.search = search;
      this.search.page = 1;
      this.searchList();
    },
    searchList() {
      this.loading = true;
      const para = Object.assign({}, this.search);
      getextendData(para).then(res => {
        this.loading = false;
        this.pagenationData.pageTotal = res.data.count;
        this.tableData = res.data.list;
      });
    },
    // 获取待审核数据
    getextendData() {
      const para = Object.assign({}, this.pageData);
      getextendData(para).then(res => {
        this.loading = false;
        this.pagenationData.pageTotal = res.data.count;
        this.tableData = res.data.list;
      });
    },
    showdialog(row) {
      //返利信息弹框显示
      this.showRebateDialog.dialogRow = row; //将行内信息存储，方便弹框显示
      this.showRebateDialog.show = true;
    },
    playerRemark() {
      var data = this.form;
      changePlayerRemark(data).then(res => {
        let result = res.data.result;
        if (result == 2) {
          this.$message({
            type: "success",
            message: "操作成功"
          });
          setTimeout(() => {
            this.reload();
          }, 20);
        } else {
          this.$message({
            type: "warning",
            message: "操作失败"
          });
        }
      });
      this.playerRemarkVisible = false;
    },
    showNotes(row) {
      this.form.remark = row.remark;
      this.form.roId = row.roId;
      this.playerRemarkVisible = true;
    },
    showdetail(row) {
      let roId = {
        roId: row.roId
      };
      showrebateDetail(roId).then(res => {
        this.detailDialog.dialogRow = res.data.list;
        this.detailDialog.show = true;
      });
    },
    hideRebateDialog() {
      //关闭查看返利
      this.showRebateDialog.show = false;
    },
    hideDetailDialog() {
      this.detailDialog.show = false;
    },
    // 当用户手动勾选数据行的 Checkbox 时触发的事件
    selectTable(val, row) {
      this.multipleSelection = val;
    },
    //一键发放
    sendtoCP() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          type: "warning",
          message: "请至少选择一项！"
        });
      } else {
        this.$confirm(
          `确定一键发放选中的 ${this.multipleSelection.length} 条数据吗？`,
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }
        ).then(() => {
          var roIdArr = [];
          this.multipleSelection.forEach(item => {
            roIdArr.push(item.roId);
          });
          let roIdStr = roIdArr.join(",");
          let params = {
            roIds: roIdStr
          };
          onekeyExtend(params).then(res => {
            let result = res.data.result;
            if (result == 2) {
              this.$message({
                type: "success",
                message: "操作成功"
              });
              setTimeout(() => {
                this.reload();
              }, 20);
            } else {
              this.$message({
                type: "warning",
                message: "操作失败"
              });
            }
          });
        });
      }
    },
    // 行内发放
    giveOut(row) {
      let roId = row.roId;
      let roIdParm = { roId };
      giveOutInline(roIdParm).then(res => {
        let result = res.data.result;
        if (result == 2) {
          this.$message({
            type: "success",
            message: "操作成功"
          });
          setTimeout(() => {
            this.reload();
          }, 20);
        } else {
          this.$message({
            type: "warning",
            message: "操作失败"
          });
        }
      });
    },
    // 上下分页
    handleCurrentChange(val) {
      this.pageData.page = val;
      this.search.page = val;
      this.searchList();
    }
  }
};
</script>
<style lang="scss">
.extend {
  .el-button.el-button--success,
  .el-button.el-button--danger {
    padding: 5px 7px;
  }
  .el-button + .el-button {
    margin-left: 5px;
  }
  .el-button:active {
    border-color: transparent;
  }
}
.el-message-box--center .el-message-box__header {
  padding-top: 20px;
}
.el-message-box--center {
  padding-bottom: 20px;
}
.el-message-box__btns {
  margin-top: 10px;
}
</style>



